package com.leapp.sk.ui.adapter

import android.content.Context
import android.content.Intent
import android.view.View
import com.example.mvp.adapter.BaseLibMultipleViewAdapter
import com.example.mvp.binder.BaseDataBinder
import com.example.mvp.delegate.BaseAdapterDelegate
import com.example.util.ISTECHER
import com.leapp.sk.R
import com.leapp.sk.bean.ParentingTaskEntity
import com.leapp.sk.binder.BaseBinder
import com.leapp.sk.ui.activity.task.ParentTaskCompleteDegreeActivity
import com.leapp.sk.viewdelegate.adapter.task.ParentingTaskAdapterDelegate
import com.leapp.sk.viewdelegate.adapter.task.TeacherParentingTaskAdapterDelegate

/**
 * 亲子作业适配器
 * @author  chaohaipeng  on 2018/8/3.
 */
class ParentingTaskAdapter  (context: Context, mlist: List<ParentingTaskEntity>) : BaseLibMultipleViewAdapter< ParentingTaskEntity>(context, mlist){
    /**
     * 数据
     */
    val mList = mlist
    /**
     * 上下文
     */
    val mContext = context


    override fun bindEvenListener(viewDelegate: BaseAdapterDelegate?, position: Int) {
         if (viewDelegate is TeacherParentingTaskAdapterDelegate){
             viewDelegate.setOnClickListener(View.OnClickListener {
                 val intent= Intent(mContext, ParentTaskCompleteDegreeActivity::class.java)
                 mContext.startActivity(intent)
             }, R.id.tv_atpt_complete_num)
         }else{


         }


    }

    override fun notifyView(viewDelegate: BaseAdapterDelegate?, position: Int) {
        if (viewDelegate is ParentingTaskAdapterDelegate){
            viewDelegate.initData(mContext,mList.get(position))
        }
    }

    override fun getDelegate(position: Int): BaseAdapterDelegate {
        if (ISTECHER){
            return TeacherParentingTaskAdapterDelegate::class.java?.newInstance()
        }else{
            return ParentingTaskAdapterDelegate::class.java?.newInstance()
        }
    }

    override fun getDataBinder(position: Int): BaseDataBinder<*, *> {
        return BaseBinder()
    }

    override fun getItemData(position: Int): Any {
       return mList.get(position)
    }

}